package com.undsf.despot.templates;

import com.undsf.despot.modles.Identify;
import com.undsf.despot.modles.Identify64;
import com.undsf.despot.modles.Skill;
import com.undsf.utility.TemplateEngine;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Arathi on 2016/10/4.
 */
public class SkillTemplateBase {
    protected String id;  // 不可继承
    protected String parent;  // 不可继承
    protected String name;
    protected String alias;  // 解析模板时使用，不用传递到Skill
    protected String spell;
    protected Integer cost_mp;
    protected String buff;
    protected Integer damage_min;
    protected Integer damage_max;
    protected Integer heal_min;
    protected Integer heal_max;
    protected Integer target_type;
    protected Integer effect_type;
    protected String cast_description;
    protected String description;
    protected Integer active;  // 是否为主动技能
    protected Double amendment;  // 属性修正值
    protected String property;  // 技能属性 （gira、rariho、hahoton、fire）

    public Skill create() {
        Skill skill = new Skill();

        skill.setId(new Identify64(id));
        skill.setParent(new Identify64(parent));
        skill.setName (name);
        skill.setSpell(spell);
        skill.setCostMp((cost_mp==null) ? 0 : cost_mp.intValue());
        skill.setBuff((buff==null) ? null : new Identify64(buff));
        skill.setTargetType((target_type==null) ? 0 : target_type.intValue());
        skill.setEffectType((effect_type==null) ? 0 : effect_type.intValue());
        skill.setDamageMin((damage_min==null) ? 0 : damage_min.intValue());
        skill.setDamageMax((damage_max==null) ? 0 : damage_max.intValue());
        skill.setHealMin((heal_min==null) ? 0 : heal_min.intValue());
        skill.setHealMax((heal_max==null) ? 0 : heal_max.intValue());
        skill.setDescription(description);
        skill.setActive((active==null) ? false : (active>0));
        skill.setAmendment((amendment==null) ? 0 : amendment.doubleValue());
        skill.setProperty(property);
        skill.setCastDescription(formatCastDescription());
        return skill;
    }

    public void inherit(SkillTemplateBase parent) {
        if (name == null) name = parent.name;
        if (alias == null) alias = parent.alias;
        if (spell == null) spell = parent.spell;
        if (cost_mp == null) cost_mp = parent.cost_mp;
        if (buff == null) buff = parent.buff;
        if (damage_min == null) damage_min = parent.damage_min;
        if (damage_max == null) damage_max = parent.damage_max;
        if (heal_min == null) heal_min = parent.heal_min;
        if (heal_max == null) heal_max = parent.heal_max;
        if (target_type == null) target_type = parent.target_type;
        if (effect_type == null) effect_type = parent.effect_type;
        if (cast_description == null) cast_description = parent.cast_description;
        if (description == null) description = parent.description;
        if (active == null) active = parent.active;
        if (amendment == null) amendment = parent.amendment;
        if (property == null) property = parent.property;
    }

    public String formatCastDescription() {
        Map<String,String> params = new HashMap<String,String>();
        // 目前只有这些参数
        params.put("name", name);
        params.put("alias", alias);
        return TemplateEngine.Parse(cast_description, params);
    }

    @Override
    public String toString() {
        return id+" "+name;
    }

    // =======================


    public String getId() {
        return id;
    }

    public String getParent() {
        return parent;
    }

    public String getName() {
        return name;
    }

    public String getAlias() {
        return alias;
    }

    public String getSpell() {
        return spell;
    }

    public Integer getCost_mp() {
        return cost_mp;
    }

    public String getBuff() {
        return buff;
    }

    public Integer getDamage_min() {
        return damage_min;
    }

    public Integer getDamage_max() {
        return damage_max;
    }

    public Integer getHeal_min() {
        return heal_min;
    }

    public Integer getHeal_max() {
        return heal_max;
    }

    public Integer getTarget_type() {
        return target_type;
    }

    public Integer getEffect_type() {
        return effect_type;
    }

    public String getCast_description() {
        return cast_description;
    }

    public String getDescription() {
        return description;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public void setSpell(String spell) {
        this.spell = spell;
    }

    public void setCost_mp(Integer cost_mp) {
        this.cost_mp = cost_mp;
    }

    public void setBuff(String buff) {
        this.buff = buff;
    }

    public void setDamage_min(Integer damage_min) {
        this.damage_min = damage_min;
    }

    public void setDamage_max(Integer damage_max) {
        this.damage_max = damage_max;
    }

    public void setHeal_min(Integer heal_min) {
        this.heal_min = heal_min;
    }

    public void setHeal_max(Integer heal_max) {
        this.heal_max = heal_max;
    }

    public void setTarget_type(Integer target_type) {
        this.target_type = target_type;
    }

    public void setEffect_type(Integer effect_type) {
        this.effect_type = effect_type;
    }

    public void setCast_description(String cast_description) {
        this.cast_description = cast_description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

    public Double getAmendment() {
        return amendment;
    }

    public void setAmendment(Double amendment) {
        this.amendment = amendment;
    }

    public String getProperty() {
        return property;
    }

    public void setProperty(String property) {
        this.property = property;
    }
}
